﻿using Microsoft.Practices.Unity;
using System;

namespace UnityDemo.Demo2
{
    public class MyClass : IClass
    {
        public MyClass()
        { }

        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="subject"></param>
        [InjectionConstructor]
        public MyClass(ISubject subject)
        {
            this.TempSubject1 = subject;
        }

        /// <summary>
        /// 属性注入
        /// </summary>
        [Dependency("Subject1")]
        public ISubject Subject { get; set; }

        public ISubject TempSubject1 { get; set; }
        public ISubject TempSubject2 { get; set; }
        public string Description { get; set; }
        public string Name { get; set; }

        /// <summary>
        /// 方法注入
        /// </summary>
        /// <param name="subjectInfo"></param>
        [InjectionMethod]
        public void Init(ISubject subjectInfo)
        {
            this.TempSubject2 = subjectInfo;
        }

        public void ShowInfo()
        {
            Console.WriteLine("构造注入成功后临时科目1名称：" + this.TempSubject1.Name);
            Console.WriteLine("属性注入成功后临时科目名称：" + this.Subject.Name);
            Console.WriteLine("方法注入成功后临时科目2名称：" + this.TempSubject2.Name);
        }
    }
}